00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef DESTRING_HPP
00029 #define DESTRING_HPP
00030
00031 #include "deGlobalTypes.hpp"
00032 #include "deArray.hpp"
00033
00034 #if defined(DEUTIL_DLL_EXPORTS) || defined(DESTINY3D_EXPORT_ALL)
00035 # define DESTRING_API DEDLL_EXPORT
00036 #elif defined(DESTINY3D_STATIC_LINK)
00037 # define DESTRING_API
00038 #else
00039 # define DESTRING_API DEDLL_IMPORT
00040 #endif
00041
00042 #ifdef USING_DESTINY3D
00043 #ifdef _DEBUG
00044 # ifdef DESTINY3D_STATIC_LINK
00045 # pragma comment(lib, "deUtil_sd")
00046 # else
00047 # pragma comment(lib, "deUtild")
00048 # endif //DESTINY3D_STATIC_LINK
00049 #else
00050 # ifdef DESTINY3D_STATIC_LINK
00051 # pragma comment(lib, "deUtil_s")
00052 # else
00053 # pragma comment(lib, "deUtil")
00054 # endif //DESTINY3D_STATIC_LINK
00055 #endif //_DEBUG
00056 #endif //USING_DESTINY3D
00057
00058
00059
00060 class DESTRING_API deString
00061 {
00062 public:
00063 deString();
00064 deString(const char * rhs);
00065 deString(const deString &rhs );
00066 ~deString();
00067
00068 long inline Length() const { return m_Length; }
00069 long inline size() const { return m_Length; }
00070
00071 deString operator+(const deString & rhs) const;
00072 deString operator+(const char * rhs) const;
00073
00074 const deString& operator+=(const deString & rhs);
00075 const deString& operator+=(const char * rhs);
00076 const deString& operator+=(const char rhs);
00077
00078 const deString & operator=(const deString & rhs);
00079 const deString & operator=(const char * rhs);
00080
00081 void SetCaseSensitivity(deBoolean Sensitive);
00082 deBoolean operator==(const deString & rhs) const;
00083 deBoolean operator==(const char * rhs) const;
00084 deBoolean operator!=(const deString & rhs) const;
00085 deBoolean operator!=(const char * rhs) const;
00086
00087 char operator[](long index) const;
00088 char& operator[](long index);
00089
00090 void operator << (char c);
00091 void operator << (long l);
00092 void operator << (unsigned long ul);
00093 void operator << (int i) {operator<<((long)i);}
00094 void operator << (unsigned int ui) {operator<<((unsigned long)ui);}
00095 void operator << (s64 i);
00096 void operator << (u64 ui);
00097 void operator << (float f);
00098 void operator << (double d);
00099 void operator << (const char * str);
00100 void operator << (const deString& str);
00101
00102 int Format(const char * format, ...);
00103
00104 int Find(char ToFind, deBoolean FindLast);
00105 void Replace(char Find, char Replace);
00106 void Split(char Splitter, deTArray <deString> &ResultStrings);
00107 deBoolean Strip(const deString &Stripped, deString &Result);
00108 deString SubString(int start, int stop);
00109
00110 const char * const_str() const { return m_String; }
00111 char * c_str() { return m_String; }
00112 char * Reserve(int Length);
00113 deBoolean Trim(int Length = -1);
00114
00115 #ifndef _CRTDBG_MAP_ALLOC
00116 void *operator new (size_t Size);
00117 void operator delete (void *p);
00118 void *operator new (size_t Size, void* buffer);
00119 void operator delete (void *p, void* buffer);
00120 void *operator new[] (size_t Size);
00121 void *operator new[] (size_t Size, int, char *, int);
00122 void operator delete[] (void *p);
00123 void operator delete[] (void *p, int, char *, int);
00124 #endif
00125
00126 private:
00127 long m_Length;
00128 deBoolean m_CaseSensitive;
00129 #ifndef DESTRING2
00130 char * m_String;
00131 long m_Alloc;
00132 char * Copy() const;
00133 void Resize(long newsize);
00134 #else
00135 deTArray<char> m_StringArr;
00136 #endif
00137 };
00138
00139
00140
00141
00142
00143
00144 class DESTRING_API deString2
00145 {
00146 public:
00147 enum string_flag
00148 {
00149 search_forwards = 0,
00150 search_backwards,
00151 flag_32bit = 0x7fffffff
00152 };
00153 #ifdef _UNICODE
00154 typedef wchar_t deString_char;
00155 #else
00156 typedef char deString_char;
00157 #endif
00158 private:
00159 class StringData
00160 {
00161 protected:
00162 ~StringData()
00163 {
00164 delete mString;
00165 }
00166 public:
00167 long mRefs;
00168 deString_char * mString;
00169 long mLength;
00170 long mAlloc;
00171 public:
00172 inline StringData() : mRefs(1), mString(0), mLength(0), mAlloc(0) {}
00173 StringData(const StringData & ref);
00174 StringData(const deString_char* str);
00175 StringData(long max_len);
00176 inline long Claim()
00177 {
00178 ++mRefs;
00179 return mRefs;
00180 }
00181 inline long Release()
00182 {
00183 --mRefs;
00184 if (mRefs == 0){
00185 delete this;
00186 return 0;
00187 }
00188 return mRefs;
00189 }
00190 StringData* getModString();
00191 };
00192
00193 StringData* mData;
00194 deBoolean mCaseSensitive;
00195
00196 void resizeData(long newlen);
00197 void OwnBuffer();
00198 deString_char * c_str();
00199 deString2(StringData* ref);
00200 public:
00201 deString2();
00202 deString2(const deString_char * ref);
00203 deString2(const deString2 &ref);
00204 ~deString2();
00205
00206 void reserve(long max_size);
00207 void resize(long size);
00208
00209 inline long size() const { return mData->mLength; }
00210 inline void SetCaseSensitivity(deBoolean Sensitive) { mCaseSensitive = Sensitive; }
00211
00212 inline const deString_char * const_str() const { return mData->mString; }
00213
00214
00215 deString_char get_at(long index) const;
00216
00217 void set_at(long index, deString_char ch);
00218
00219
00220 deString2 operator+(const deString2 & rhs) const;
00221
00222
00223 void operator+=(const deString2 & rhs);
00224
00225 void operator+=(const deString_char * str);
00226
00227
00228 void operator=(const deString2 & rhs);
00229
00230
00231 bool operator==(const deString2 & rhs) const;
00232
00233 bool operator!=(const deString2 & rhs) const;
00234
00235 bool operator==(const deString_char * rhs) const;
00236
00237 bool operator!=(const deString_char * rhs) const;
00238
00239 bool operator<(const deString2 & rhs) const;
00240
00241 bool operator<(const deString_char * rhs) const;
00242
00243
00244
00245 void Replace(deString_char find, deString_char replace);
00246
00247
00248 long Find(deString_char find, long start_at = 0, string_flag search_order = search_forwards) const;
00249
00250 void Trim(long newsize);
00251 deString2 DropChars(const deString2 &Chars) const;
00252
00253 deString2 SubString(int start, int stop) const;
00254
00255 void ToLower();
00256
00257 void ToUpper();
00258
00259 u32 Hash() const;
00260 };
00261
00262 #endif